<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title> - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content=" - 天地维杰网" />
    <meta name="description" content="天地维杰网 | 博客 | 软件 | 架构 | Java "> 
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7826003325059020" crossorigin="anonymous"></script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/mac/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />jvm
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/c/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-empty"></i> <br />c语言
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/web3/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-web3"></i> <br />web3
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/spring%E8%87%AA%E5%B8%A6%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0threadpooltaskexecutor/" itemprop="url">
        
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="0001-01-01">
    0001-01-01
</time>
</span> 
      
      
       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">262 字 ~2分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    

    

<h1 id="spring自带的线程池threadpooltaskexecutor">Spring自带的线程池ThreadPoolTaskExecutor</h1>

<h2 id="前言">前言</h2>

<p>上一篇分享了JDK自带的线程池ThreadPoolExecutor的配置和参数详解，然而我们实际开发中更多的是使用SpringBoot来开发，Spring默认也是自带了一个线程池方便我们开发，它就是ThreadPoolTaskExecutor，接下来我们就来聊聊Spring的线程池吧。</p>

<h2 id="spring默认线程池simpleasynctaskexecutor">Spring默认线程池simpleAsyncTaskExecutor</h2>

<p>Spring异步线程池的接口类是TaskExecutor，本质还是java.util.concurrent.Executor，没有配置的情况下，默认使用的是simpleAsyncTaskExecutor。</p>

<p><strong>@Async演示Spring默认的simpleAsyncTaskExecutor</strong></p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#5c35cc;font-weight:bold">@Component</span>
<span style="color:#5c35cc;font-weight:bold">@EnableAsync</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">ScheduleTask</span> <span style="color:#ce5c00;font-weight:bold">{</span>

    <span style="color:#000">SimpleDateFormat</span> <span style="color:#000">sdf</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">SimpleDateFormat</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;yyyy-MM-dd HH:mm:ss&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>

    <span style="color:#5c35cc;font-weight:bold">@Async</span>
    <span style="color:#5c35cc;font-weight:bold">@Scheduled</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">fixedRate</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">2000</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">testScheduleTask</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">Thread</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">sleep</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">6000</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Spring1自带的线程池&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">Thread</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentThread</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getName</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;-&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">sdf</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">format</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Date</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">InterruptedException</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@Async</span>
    <span style="color:#5c35cc;font-weight:bold">@Scheduled</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">cron</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;*/2 * * * * ?&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">testAsyn</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">Thread</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">sleep</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">1000</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Spring2自带的线程池&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">Thread</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentThread</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getName</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;-&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">sdf</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">format</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Date</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">ex</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">ex</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220316170141.png" width = 900 /> </div>

<p>从运行结果可以看出Spring默认的@Async用线程池名字为SimpleAsyncTaskExecutor，而且每次都会重新创建一个新的线程，所以可以看到TaskExecutor-后面带的数字会一直变大。</p>

<p>simpleAsyncTaskExecutor的特点是，每次执行任务时，它会重新启动一个新的线程，并允许开发者控制并发线程的最大数量（concurrencyLimit），从而起到一定的资源节流作用。默认是concurrencyLimit取值为-1，即不启用资源节流。</p>

<h2 id="spring的线程池threadpooltaskexecutor">Spring的线程池ThreadPoolTaskExecutor</h2>

<p>上面介绍了Spring默认的线程池simpleAsyncTaskExecutor，但是Spring更加推荐我们开发者使用ThreadPoolTaskExecutor类来创建线程池，其本质是对java.util.concurrent.ThreadPoolExecutor的包装。</p>

<p>这个类则是spring包下的，是Spring为我们开发者提供的线程池类，这里重点讲解这个类的用法。</p>

<p>Spring提供了xml给我们配置ThreadPoolTaskExecutor线程池，但是现在普遍都在用SpringBoot开发项目，所以直接上yaml或者properties配置即可，或者也可以使用@Configuration配置也行，下面演示配置和使用。</p>

<h2 id="threadpooltaskexecutor配置">ThreadPoolTaskExecutor配置</h2>

<p>application.properties</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#a40000">#</span> <span style="color:#000">核心线程池数</span>
<span style="color:#000">spring</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">task</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">execution</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">pool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">core</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">size</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">5</span>
<span style="color:#a40000">#</span> <span style="color:#000">最大线程池数</span>
<span style="color:#000">spring</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">task</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">execution</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">pool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">max</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">size</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">10</span>
<span style="color:#a40000">#</span> <span style="color:#000">任务队列的容量</span>
<span style="color:#000">spring</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">task</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">execution</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">pool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">queue</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">capacity</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">5</span>
<span style="color:#a40000">#</span> <span style="color:#000">非核心线程的存活时间</span>
<span style="color:#000">spring</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">task</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">execution</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">pool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">keep</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">alive</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">60</span>
<span style="color:#a40000">#</span> <span style="color:#000">线程池的前缀名称</span>
<span style="color:#000">spring</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">task</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">execution</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">thread</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">prefix</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">god</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">jiang</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">task</span><span style="color:#ce5c00;font-weight:bold">-</span></code></pre></div>
<p>AsyncScheduledTaskConfig.java</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#5c35cc;font-weight:bold">@Configuration</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">AsyncScheduledTaskConfig</span> <span style="color:#ce5c00;font-weight:bold">{</span>

    <span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${spring.task.execution.pool.core-size}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">corePoolSize</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${spring.task.execution.pool.max-size}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">maxPoolSize</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${spring.task.execution.pool.queue-capacity}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">queueCapacity</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${spring.task.execution.thread-name-prefix}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#000">String</span> <span style="color:#000">namePrefix</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${spring.task.execution.pool.keep-alive}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">keepAliveSeconds</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#5c35cc;font-weight:bold">@Bean</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Executor</span> <span style="color:#000">myAsync</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">ThreadPoolTaskExecutor</span> <span style="color:#000">executor</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">ThreadPoolTaskExecutor</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//最大线程数
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setMaxPoolSize</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">maxPoolSize</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//核心线程数
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setCorePoolSize</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">corePoolSize</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//任务队列的大小
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setQueueCapacity</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">queueCapacity</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//线程前缀名
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setThreadNamePrefix</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">namePrefix</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//线程存活时间
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setKeepAliveSeconds</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">keepAliveSeconds</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>

        <span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic">         * 拒绝处理策略
</span><span style="color:#8f5902;font-style:italic">         * CallerRunsPolicy()：交由调用方线程运行，比如 main 线程。
</span><span style="color:#8f5902;font-style:italic">         * AbortPolicy()：直接抛出异常。
</span><span style="color:#8f5902;font-style:italic">         * DiscardPolicy()：直接丢弃。
</span><span style="color:#8f5902;font-style:italic">         * DiscardOldestPolicy()：丢弃队列中最老的任务。
</span><span style="color:#8f5902;font-style:italic">         */</span>
        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setRejectedExecutionHandler</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">ThreadPoolExecutor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">AbortPolicy</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//线程初始化
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">initialize</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<p>在方法上添加@Async注解，然后还需要在@SpringBootApplication启动类或者@Configuration注解类上 添加注解@EnableAsync启动多线程注解，@Async就会对标注的方法开启异步多线程调用，注意，这个方法的类一定要交给Spring容器来管理</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#5c35cc;font-weight:bold">@Component</span>
<span style="color:#5c35cc;font-weight:bold">@EnableAsync</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">ScheduleTask</span> <span style="color:#ce5c00;font-weight:bold">{</span>

    <span style="color:#000">SimpleDateFormat</span> <span style="color:#000">sdf</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">SimpleDateFormat</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;yyyy-MM-dd HH:mm:ss&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>

    <span style="color:#5c35cc;font-weight:bold">@Async</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;myAsync&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@Scheduled</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">fixedRate</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">2000</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">testScheduleTask</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">Thread</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">sleep</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">6000</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Spring1自带的线程池&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">Thread</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentThread</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getName</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;-&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">sdf</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">format</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Date</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">InterruptedException</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@Async</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;myAsync&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@Scheduled</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">cron</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;*/2 * * * * ?&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">testAsyn</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">Thread</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">sleep</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">1000</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Spring2自带的线程池&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">Thread</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentThread</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getName</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;-&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">sdf</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">format</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Date</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">ex</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">ex</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220316170218.png" width = 900 /> </div>

<p>以上从运行结果可以看出，自定义ThreadPoolTaskExecutor可以实现线程的复用，而且还能控制好线程数，写出更好的多线程并发程序。</p>

<p><strong>另外需要注意的是：关于注解失效需要注意以下几点</strong></p>

<ol>
<li>注解的方法必须是public方法</li>
<li>方法一定要从另一个类中调用，也就是从类的外部调用，类的内部调用是无效的，因为@Transactional和@Async注解的实现都是基于Spring的AOP，而AOP的实现是基于动态代理模式实现的。那么注解失效的原因就很明显了，有可能因为调用方法的是对象本身而不是代理对象，因为没有经过Spring容器。</li>
<li>异步方法使用注解@Async的返回值只能为void或者Future</li>
</ol>

<p><strong>上面注解中已经注释了参数的详解，这里重点讲解一下Spring线程池的拒绝策略和处理流程。</strong></p>

<h2 id="拒绝策略"><strong>拒绝策略</strong></h2>

<p><strong>rejectedExectutionHandler参数字段用于配置绝策略，常用拒绝策略如下</strong></p>

<ul>
<li>AbortPolicy：用于被拒绝任务的处理程序，它将抛出RejectedExecutionException</li>
<li>CallerRunsPolicy：用于被拒绝任务的处理程序，它直接在execute方法的调用线程中运行被拒绝的任务。</li>
<li>DiscardOldestPolicy：用于被拒绝任务的处理程序，它放弃最旧的未处理请求，然后重试execute。</li>
<li>DiscardPolicy：用于被拒绝任务的处理程序，默认情况下它将丢弃被拒绝的任务。</li>
</ul>

<h2 id="处理流程">处理流程</h2>

<ol>
<li>查看核心线程池是否已满，不满就创建一条线程执行任务，否则执行第二步。</li>
<li>查看任务队列是否已满，不满就将任务存储在任务队列中，否则执行第三步。</li>
<li>查看线程池是否已满，即就是是否达到最大线程池数，不满就创建一条线程执行任务，否则就按照策略处理无法执行的任务。</li>
</ol>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220316170239.png" width = 600 /> </div>

<h2 id="总结">总结</h2>

<p>这次分享了Spring自带的线程池ThreadPoolTaskExecutor的配置和使用，并且讲了线程池的参数和处理流程。当然Spring提供了7个线程池的实现，感兴趣的可以自行了解～～～</p>

<p>希望以上的分享对你们有所帮助，喜欢的点个赞支持一下我吧～～～</p>

    </div>
    <footer class="post-footer">
     

     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/springboot2.x-%E9%9B%86%E6%88%90-jedis%E5%92%8Cspring-boot-starter-data-redis%E7%9A%84%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95%E6%AF%94%E8%BE%83jedis%E5%AE%8C%E8%83%9C%E9%99%84%E5%B8%A6%E6%BA%90%E7%A0%81/" rel="next" title="">
        <i class="fa fa-chevron-left"></i> 
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/spring%E8%8E%B7%E5%8F%96-maven-profile/" rel="prev" title="">
         <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

    <section class="site-overview sidebar-panel  sidebar-panel-active ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">183</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">15</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">224</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2023</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>